import type { Request } from 'express'
import { todoService } from '@server/services/todo-service'
import { ApiResponse } from '@data/api'
import { NotFoundError } from '@server/error/errors'

export default async function deleteTodo(request: Request) {
  const id = request.params.id

  const success = await todoService.deleteTodo(id)

  if (!success) {
    throw new NotFoundError('Todo not found')
  }

  const response: ApiResponse = {
    success: true,
    message: 'Todo deleted successfully',
  }

  return response
}
